package com.keshe.cart.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.keshe.cart.entity.UcouponEntity;
import com.keshe.cart.service.UcouponService;
import com.keshe.common.utils.PageUtils;
import com.keshe.common.utils.R;



/**
 *
 *
 * @author xiongsiyi
 * @email 2825889385@qq.com
 * @date 2023-01-02 14:12:01
 */
@RefreshScope
@RestController
@RequestMapping("cart/ucoupon")
public class UcouponController {
    @Autowired
    private UcouponService ucouponService;

    /**
     * 测试用户优惠券
     */
    @RequestMapping("/member/list")
    public R memberCoupons(){
        UcouponEntity ucouponEntity = new UcouponEntity();
        ucouponEntity.setCouponid(1);
        return R.ok().put("coupons", Arrays.asList(ucouponEntity));
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("cart:ucoupon:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = ucouponService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("cart:ucoupon:info")
    public R info(@PathVariable("id") Integer id){
		UcouponEntity ucoupon = ucouponService.getById(id);

        return R.ok().put("ucoupon", ucoupon);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("cart:ucoupon:save")
    public R save(@RequestBody UcouponEntity ucoupon){
		ucouponService.save(ucoupon);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("cart:ucoupon:update")
    public R update(@RequestBody UcouponEntity ucoupon){
		ucouponService.updateById(ucoupon);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("cart:ucoupon:delete")
    public R delete(@RequestBody Integer[] ids){
		ucouponService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
